/**
 * Imported packages
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @authors BENSON WACHIRA, DOROTHY SARPONG, STANLEY ANKU
 * MICHAEL ESHUN & MAKAFUI AMEZAH
 */

/**
 * 
 * A controller class for the homepage form
 */
public class ControllerHomePage {
    /**
     * Object declarations
     */
    public HomePage home;
    private ActionListener actionListener;
    
    /**
     * Object declarations ad instantiations
     */
    EnterForm addOrder= new EnterForm();
    ListOrders listOrder= new ListOrders();
    DeleteOrder deleteOrder=new DeleteOrder();
    ModifyOrder modifyOrder=new ModifyOrder();
    EnterFlight enterFlight= new EnterFlight();
    ModifyFlight modifyFlight=new ModifyFlight();
    DeleteFlight deleteFlight = new DeleteFlight();
    ListFlights listFlight = new ListFlights();
    EnterEmployee addEmployee = new EnterEmployee();
    ListEmployees listEmployee = new ListEmployees();
    ModifyEmployee modifyEmployee = new ModifyEmployee();
    DeleteEmployee deleteEmployee= new DeleteEmployee();
    
    /**
     * Constructor
     */
    public ControllerHomePage( ){
        home = new HomePage();
        home.setVisible(true);
    }
    
    /**
     * Method to get source of button clicked using action listener
     */
    public void control(){        
        actionListener = new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) { 
                  if(actionEvent.getSource()==home.getAddEmp()){ 
                      ControllerAddEmp add= new ControllerAddEmp();
                         add.contol();
                  }
                  if(actionEvent.getSource()==home.getModifyEmp()){
                      ControllerModifyEmp c= new ControllerModifyEmp();
                        c.control(); 
                  }
                  if(actionEvent.getSource()==home.getDeleteEmp()){
                      ControllerDeleteEmp delete= new ControllerDeleteEmp();
                        delete.contol();
                  }
                  if(actionEvent.getSource()==home.getShowEmp()){
                      ControllerListEmp cE= new ControllerListEmp();
                        cE.contol();
                  }
                  if(actionEvent.getSource()==home.getAddFlight()){  
                      ControllerAddFlight c= new ControllerAddFlight();
                     c.contol();
                  }
                  if(actionEvent.getSource()==home.getModifyFlight()){
                      ControllerModifyFlight c = new ControllerModifyFlight();
                        c.control();
                  }
                  if(actionEvent.getSource()==home.getDeleteFlight()){
                      ControllerDeleteFlight deleteF= new ControllerDeleteFlight();
                        deleteF.contol();
                  }
                  if(actionEvent.getSource()==home.getShowFlight()){
                      ControllerListFlight cF= new ControllerListFlight();
                        cF.contol();
                  }
                  if(actionEvent.getSource()==home.getAddReservation()){
                      ControllerAddOrder Ao= new ControllerAddOrder();
                      Ao.contol();
                      Ao.contolCombo();
                  }
                  if(actionEvent.getSource()==home.getModifyReservation()){
                       ControllerModifyOrder c= new ControllerModifyOrder();
                        c.control();
                  }
                  if(actionEvent.getSource()==home.getDeleteReservation()){
                      DeleteOrderController deleteO= new DeleteOrderController();
                        deleteO.control();
                  }
                  if(actionEvent.getSource()==home.getShowReservation()){
                      ControllerListOrders cLO= new ControllerListOrders();
                         cLO.contol();
                  }
                                    
                   if(actionEvent.getSource()==home.getAddEmMenu()){ 
                      ControllerAddEmp add= new ControllerAddEmp();
                         add.contol();
                  }
                  if(actionEvent.getSource()==home.getModifyEmMenu()){
                       ControllerModifyEmp c= new ControllerModifyEmp();
                    c.control(); 
                  }
                  if(actionEvent.getSource()==home.getDeleteEmMenu()){
                      ControllerDeleteEmp delete= new ControllerDeleteEmp();
                        delete.contol();
                  }
                  if(actionEvent.getSource()==home.getShowEmMenu()){
                      ControllerListEmp cE= new ControllerListEmp();
                        cE.contol();
                  }
                  if(actionEvent.getSource()==home.getAddFlMenu()){  
                      ControllerAddFlight c= new ControllerAddFlight();
                     c.contol();
                  }
                  if(actionEvent.getSource()==home.getModifyFlMenu()){
                       ControllerModifyFlight c = new ControllerModifyFlight();
                        c.control();
                  }
                  if(actionEvent.getSource()==home.getDeleteFlMenu()){
                      ControllerDeleteFlight deleteF= new ControllerDeleteFlight();
                        deleteF.contol();
                  }
                  if(actionEvent.getSource()==home.getShowFlMenu()){
                      ControllerListFlight cF= new ControllerListFlight();
                        cF.contol();
                  }
                  if(actionEvent.getSource()==home.getAddReMenu()){
                      ControllerAddOrder Ao= new ControllerAddOrder();
                      Ao.contol();
                      Ao.contolCombo();
                  }
                  if(actionEvent.getSource()==home.getModifyReMenu()){
                       ControllerModifyOrder c= new ControllerModifyOrder();
                      c.control();
                  }
                  if(actionEvent.getSource()==home.getDeleteReMenu()){
                      DeleteOrderController deleteO= new DeleteOrderController();
                        deleteO.control();
                  }
                  if(actionEvent.getSource()==home.getShowReMenu()){
                      ControllerListOrders cLO= new ControllerListOrders();
                         cLO.contol();
                  }
                  if(actionEvent.getSource()==home.getListOrders()){
                     ControllerDataDisplayList c= new ControllerDataDisplayList();
                        c.control();
                  }
                  if(actionEvent.getSource()==home.getExport()){
                     ControllerExport cont= new ControllerExport();
                     cont.listOrders();
                  }
                  if(actionEvent.getSource()==home.getSearchButton()){;
                       java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run(){ 
                      JET_Wing_MyForm view1= new JET_Wing_MyForm();
                        Search_Flight_Controller controller = new Search_Flight_Controller(view1);
               
                        controller.control();
                
            }
        });
                  }
                  
                  }
              
        };
        /**
         *  ActionListener buttons
         */
        home.getAddEmp().addActionListener(actionListener);
        home.getModifyEmp().addActionListener(actionListener);
        home.getDeleteEmp().addActionListener(actionListener);
        home.getShowEmp().addActionListener(actionListener);
        home.getAddFlight().addActionListener(actionListener);
        home.getModifyFlight().addActionListener(actionListener);
        home.getDeleteFlight().addActionListener(actionListener);
        home.getShowFlight().addActionListener(actionListener);
        home.getAddReservation().addActionListener(actionListener);
        home.getModifyReservation().addActionListener(actionListener);
        home.getDeleteReservation().addActionListener(actionListener);
        home.getShowReservation().addActionListener(actionListener);
       
   
        /**
         * MenuItems action listener
         */
        home.getAddEmMenu().addActionListener(actionListener);
        home.getModifyEmMenu().addActionListener(actionListener);
        home.getDeleteEmMenu().addActionListener(actionListener);
        home.getShowEmMenu().addActionListener(actionListener);
        home.getAddFlMenu().addActionListener(actionListener);
        home.getModifyFlMenu().addActionListener(actionListener);
        home.getDeleteFlMenu().addActionListener(actionListener);
        home.getShowFlMenu().addActionListener(actionListener);
        home.getAddReMenu().addActionListener(actionListener);
        home.getModifyReMenu().addActionListener(actionListener);
        home.getDeleteReMenu().addActionListener(actionListener);
        home.getShowReMenu().addActionListener(actionListener);
        home.getListOrders().addActionListener(actionListener);
        home.getExport().addActionListener(actionListener);
        home.getSearchButton().addActionListener(actionListener);
        
        }
     
}
